package com.nstar.countdown.view.modules.main.impl
{
	import com.nstar.base.util.SystemUtils;
	import com.nstar.countdown.model.vo.CountDownVO;
	import com.nstar.countdown.view.components.CountDownMore;
	import com.nstar.countdown.view.components.TagClouds;
	import com.nstar.countdown.view.components.ThumbnailList;
	import com.nstar.countdown.view.modules.main.ControlPanel;
	import com.nstar.countdown.view.modules.main.Header;
	
	import flash.events.MouseEvent;
	
	import mx.containers.Canvas;
	import mx.events.FlexEvent;

	public class MainClass extends Canvas
	{
		public static const CREATION_COMPLETE: String = "myCreationComplete";
		
		public var header:Header;
		public var tlMain:ThumbnailList;
		public var controlPanel:ControlPanel;
		public var tagClouds:TagClouds;
		
		public function MainClass()
		{
			super();
			this.addEventListener(FlexEvent.CREATION_COMPLETE,init);
		}
		
		private function init(event:FlexEvent):void{
			loadSampleData();
			tlMain.addEventListener(MouseEvent.CLICK,showPopUpDetail);
		}
		
		private function showPopUpDetail(event:MouseEvent):void{
			CountDownMore.show(tlMain.selectedItem as CountDownVO);
		}
		
		private function loadSampleData():void{
			var titles:Array = ["","《建国大业》首映","王力宏大陆歌迷会","第11届全国运动会","2008北京奥运开幕式",
								"INTEL杯程序设计大赛","上海旅游节开幕","2009博鳌亚洲论坛","世界之窗浏览器皮肤设计",
								"千千静听皮肤设计大赛","新街口家乐福2周年店庆"];
			var list:Array = new Array();
			for(var i:int=0;i<25;i++){
				var vo:CountDownVO = new CountDownVO();
				var num:Number = SystemUtils.randRange(1,titles.length-1);
				vo.logo = "logos/sample"+num+".jpg";
				vo.mainTitle = titles[num];
				
				var date:Date = new Date();
				date.month = SystemUtils.randRange(1,12);
				date.date = SystemUtils.randRange(1,30);
				date.fullYear = 2009+SystemUtils.randRange(0,5);
				
				vo.countDownDate = date;
				vo.tops = SystemUtils.randRange(100,1000);
				vo.comments = SystemUtils.randRange(0,100);
				list.push(vo);
			}
			tlMain.dataProvider = list;
			
			var tagNames:Array = ["汽车","手机","播放器","家电","电视机","皮肤大赛","论坛","峰会",
				"Twitter","FLEX","JAVA","九寨沟","黄山","奥运会"];
			var tags:Array = new Array();
			for(var i:int=0;i<30;i++){
				var item:Object = new Object();
				item.label = tagNames[SystemUtils.randRange(1,tagNames.length-1)];
				item.percent = SystemUtils.randRange(0,100);
				tags.push(item);
			}
			tagClouds.dataProvider = tags;
			
		}
		
	}
}